#include <bits/stdc++.h>

using namespace std;

class solution
{
public:
    int numSquares(int n)
    {
        vector<int> dp(n + 1, INT_MAX);
        for (int i = 0; i <= n; i++)
        {
            dp[i] = i;
        }
        for (int i = 2; i <= static_cast<int>(sqrt(n)); i++)
        {
            for (int j = i * i; j <= n; j++)
            {
                dp[j] = min(dp[j], dp[j - i * i] + 1);
            }
        }
        return dp[n];
    }
};

int main()
{
    solution sol;
    cout << sol.numSquares(12) << endl;
    return 0;
}